package com.property.manage.service.flowingWater;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guardchina.framework.mybatis.model.CustomPage;
import com.guardchina.framework.util.exception.BusinessException;
import com.property.manage.dao.renovation.DepositMapper;
import com.property.manage.model.renovation.DepositEntity;
import com.property.manage.model.renovation.DepositVo;
import com.property.manage.model.system.SysSet;
import com.property.manage.service.renovation.DepositService;
import com.property.manage.service.resource.BuildingService;
import com.property.manage.service.system.SysSetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Service
@Slf4j
public class HouseDepositService {
    @Autowired
    private DepositMapper depositMapper;
    @Autowired
    private DepositService depositService;
    @Autowired
    private BuildingService buildingService;
    @Value("${timed.patee}")
    private String patee;
    @Autowired
    private SysSetService sysSetService;
    //新增房屋押金
    public void add(BigDecimal money, String payer,
                    String phone, Integer buildingId, Integer villageId,
                    Integer userId,Integer printing,Integer status){
        depositService.add(money,payer,phone,buildingId,null,villageId,status,userId,printing);
    }

    //押金退还
    public void refund(Integer id, BigDecimal refund,Integer userId) {
        DepositEntity entity  = depositService.getById(id);
        if (entity == null) {
            throw new BusinessException("id错误", String.format("id:[%S]", id));
        }
        depositService.update(id,refund,3,userId);
    }

    //房屋押金列表
    public CustomPage<DepositVo> page(Long pageNo, Long pageSize,Integer villageId, Integer building, Integer unit, String roomNumber,Integer status){
        Page<DepositVo> page = new Page<>(pageNo, pageSize);
        IPage<DepositVo> village = depositMapper.getPage2(page, villageId,building,unit,roomNumber, status);
        List<DepositVo> records = village.getRecords();
        if (records.isEmpty()){
            return new CustomPage<>(village);
        }
        for (DepositVo record : records) {
            Integer status1 = record.getStatus();

        }
        return new CustomPage<>(village);
    }
}
